//
//  MaskViewController.swift
//  Matting
//  Created by JoyWT on 2022/3/4
//  
    

import UIKit
import opencv2
class MaskViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
     func pickedDone1() {
//        let od = Mat(uiImage: originalImage!) //原图
        let md = Mat(uiImage: maskImage!) //deaplab生成的mask图 ,黑色为前景区域
        //处理背景图片
        let nmd = Mat()
        Core.bitwise_not(src: md, dst: nmd) //对mask图片取反 白色为前景区域
//        let nnbd2 = Mat()
//
//         od.copy(to: nnbd2, mask: nmd)

        
        // 合并前景和背景图
//        let ed = Mat()
////        Core.add(src1: nd, src2: nnbd2, dst: ed)
//        let mnmd = Mat()
//        let w = 2
//        let k = Imgproc.getStructuringElement(shape: .MORPH_RECT, ksize: Size2i(width: Int32(w), height: Int32(w)))
//        Imgproc.morphologyEx(src: nmd, dst: mnmd, op: .MORPH_OPEN, kernel: k, anchor: Point2i(x: -1, y: -1), iterations: 1)
//        Imgproc.morphologyEx(src: nmd, dst: mnmd, op: .MORPH_OPEN, kernel: k)
//
//        imageView.image = nmd.toUIImage()
        let md1 = Mat()
        Imgproc.medianBlur(src: nmd, dst: md1, ksize: 41)
        
        imageView.image = md1.toUIImage()
        
    }
    
    override func pickedDone() {
        
        imageView.image = maskImage

    }
  
}
